<?php
/*
 * Template pour la liste des projets
 * Créer le 10-03-2013
 */

// Récupère le get parameters
global $wp_query;
if($wp_query->query_vars['choixprojet']) {
    $needChooseProject = $wp_query->query_vars['choixprojet'];
}

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
/* Requête pour aller chercher les post-type des projets */
$args = array( 'post_type' => 'projet', 'posts_per_page' => 10, 'post_status' => 'publish', 'paged'=> $paged );
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query( $args );
    
get_header();
//$cpt_name == get_post_type();
//echo 'CPT:'.$cpt_name;

?>

<div class="content" role="main">
<?php    
    if ( $wp_query->have_posts() ) {
        
        if($needChooseProject==1) { echo '<div class="wpspo-erreur-projet">'.__('Please, choose a project here', 'sponsorpress').'</div>'; }
        
        while ( $wp_query->have_posts() ) : $wp_query->the_post(); 
        //global $post;
        if(get_post_meta(get_the_id(), 'wpspo_boxdateend', true) !='') { 
            $dateProjet = get_post_meta(get_the_id(), 'wpspo_boxdateend', true);
        }
        $testProjetExpire = wpspo_compare_date($dateProjet);
        
        //echo 'COMPARE:'.$compare.' --> '.$dateProjet.' --> ID:'.get_the_id().' ::: '.get_post_meta($post->ID, 'wpspo_boxdateend', true);
        if($testProjetExpire==true) {
?>        
            <article <?php if( !empty( $rv['review'] ) ) echo $rv['review']; post_class('post-listing'); ?>>
                    <div class="post-inner">
<?php


            echo '<header class="entry-header"><h1 class="name post-title entry-title entry-title"><a href="'.post_permalink().'">'.get_the_title().'</a></h1>';
            echo '</header>';  
            echo '<div class="entry">'; 
                // check if the post has a Post Thumbnail assigned to it.
                if ( has_post_thumbnail() ) {
                    echo the_post_thumbnail('thumbnail', array('class' => 'alignleft'));
                } 
                echo get_the_excerpt();
                //echo  '&nbsp;<a href="'.get_post_permalink().'">Découvrir ce projet</a>';
                echo '<div class="clear"></div>';
                echo wpspobutton_print( __( 'See this project' , 'sponsorpress') );
                echo wpspobutton_infos_project();
            echo '</div>';
            echo '</article><div class="clear espace10"></div>';
            
        } else {
            
            $projetStatus = get_post_status( $idProjet ); // Récupère le status du post
            if($projetStatus=='publish') {
                $updateStatus = WPSPO_Object::updateStatus(get_the_id(), 'archive');
                if($updateStatus==false) { echo  'Erreur quelque part !'; }
            }
            
        }
        
        endwhile;

        
    } else {
        
        ?>
        <article <?php if( !empty( $rv['review'] ) ) echo $rv['review']; post_class('post-listing'); ?>>
            <div class="post-inner">
                <header class="entry-header">
                    <h1 class="name post-title entry-title entry-title"><?php _e( 'There are no project currently', 'sponsorpress'); ?></h1>
                </header>
            </div>
        </article>
<?php
        
    }
    

    wpspo_theme_pagination();
        
    $wp_query = null;
    $wp_query = $temp;
?>
       
</div><!-- #content -->


<?php get_sidebar(); ?>
<?php get_footer(); ?>
 

